package com.archives.blog.web.www;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.archives.blog.common.domain.entity.Article;
import com.archives.blog.common.domain.pojo.request.ArticleQueryRequest;
import com.archives.blog.manager.ArticleManager;
import com.archives.blog.web.BaseSupportController;

@Controller
@RequestMapping("/article")
public class ArticleController extends BaseSupportController{

	@Autowired
	private ArticleManager articleManager;

	@RequestMapping("/query")
	@ResponseBody
	public Page<Article> query(@RequestBody ArticleQueryRequest request){
		return articleManager.getPage(request);
	}
	
	@RequestMapping("/{id}/detail")
	public String detail(ModelMap model, @PathVariable Long id){
		Article article = articleManager.getDetail(id);
		model.addAttribute("article", article);
		router(model, "article");
		return "/www/main";
	}
}
